package com.vhall.autotest.api_test.service;

import java.util.HashMap;
import java.util.Map;

import org.junit.Assert;

import com.alibaba.fastjson.JSONObject;
import com.vhall.autotest.api_test.common.Constant;
import com.vhall.autotest.api_test.common.HttpUtil;
import com.vhall.autotest.api_test.service.code.ICode;

public class Verify {
	private static final String accessTokenUrl = Constant.apiDomain + "/api/vhallapi/v2/verify/access-token";
	public static Map<String, String> accessToken_success() {
		Map<String, String> param = new HashMap<String, String>();
		Account.setAccount(param);
		System.out.println("param:" + param);
		Map<String, String> result = new HttpUtil().requestByPostMethod(accessTokenUrl, param);
		String statusCode = result.get("statusCode");
		String resultText = result.get("resultText");
		Assert.assertNotNull(statusCode);
		Assert.assertNotNull(resultText);
		Assert.assertTrue(String.valueOf(ICode.statusCodeSuccess).equals(statusCode));
		JSONObject obj = JSONObject.parseObject(resultText);
		System.out.println("accessToken_success statusCode:" + statusCode + " obj:" + obj);
		Assert.assertTrue(obj.getString("code").equals(String.valueOf(ICode.codeSuccess)));
		return result;
	}
	
	
	public static Map<String, String> accessToken_failCheck(String account, String password, String auth_type, int assertStatusCode, int assertCode) {
		Map<String, String> param = new HashMap<String, String>();
		if(account != null){
			param.put("account", account);
		}
		if(password != null){
			param.put("password", password);
		}
		if(auth_type != null){
			param.put("auth_type", auth_type);
		}
		
		System.out.println("param:" + param);
		Map<String, String> result = new HttpUtil().requestByPostMethod(accessTokenUrl, param);
		String statusCode = result.get("statusCode");
		String resultText = result.get("resultText");
		Assert.assertNotNull(statusCode);
		Assert.assertNotNull(resultText);
		Assert.assertTrue(String.valueOf(assertStatusCode).equals(statusCode));
		JSONObject obj = JSONObject.parseObject(resultText);
		System.out.println("accessToken_failCheck obj:" + obj);
		Assert.assertTrue(obj.getString("code").equals(String.valueOf(assertCode)));
		return result;
	}
	
	public static void main(String[] args) {
		String url = "https://api.jiankongbao.com/v2/user/create.json?access_token=815da79ef2b951b582ed6b8610a5bf7f";
		new HttpUtil().requestByPostMethod(url, null).get("statusCode");
	}
}
